home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
lookup.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
8KB
|
156 lines
/*
* $Id: lookup.h,v 0.91 1994/02/20 00:06:08 zhao Pre-Release $
*
*. This file is part of BIT shareware package. After the two weeks of
* free evaluation period, you are encouraged (required) to register
* your copy for a small registration fee, which is $35 for personal use
* and $50 for commercial, government and institutional use.
*
* Copyright(c) 1993, 1994 by T.C. Zhao.
* All rights reserved.
*
* Permission to use, copy, and distribute this software in its entirety
* for non-commercial purposes is hereby granted, provided that the
* above shareware and copyright notices and this permission notice
* appear in all copies and their documentation.
*
* This software may be modified for your own use, but modified versions
* may not be distributed without prior consent of the author.
*
* This software is provided "as is" without expressed or implied
* warranty of any kind.
*
*.
* lookup tables for RGB->gray. Scale the weight so that
* no floating point multiplication is needed.
*
* The weight used for RGB->GRAY are
* R .299 ( X 256 == 76.544)
* G .587 ( X 256 == 150.272)
* B .114 ( X 256 == 29.184)
*
*
*/
#ifndef BIT_LOOKUP_H
#define BIT_LOOKUP_H
#ifdef NO_R2GLOOKUP
# define R_WEIGHT 0.299
# define G_WEIGHT 0.584
# define B_WEIGHT 0.114
# define SBITS_R2G 8 /* might larger if sizeof(int)>2 */
static const int Rw_ = (0.5+(R_WEIGHT*(1<<SBITS_R2G)));
static const int Gw_ = (0.5+(G_WEIGHT*(1<<SBITS_R2G)));
static const int Bw_ = (0.5+(B_WEIGHT*(1<<SBITS_R2G)));
# define RGB2GRAY(r,g,b) ((Rw_*(r)+Gw_*(g)+Bw_*(b))>>SBITS_R2G)
#else /* use lookup tables */
# define SBITS_R2G 8 /* if not 8, need to regenerate table */
# define RGB2GRAY(r,g,b) ((mul77[r] + mul150[g]+ mul29[b])>>SBITS_R2G)
/* now the lookup tables */
#ifdef CONVERT_TYPE /* defination for table */
int mul77[256] = {
0, 77, 153, 230, 306, 383, 459, 536, 612, 689, 765, 842,
919, 995, 1072, 1148, 1225, 1301, 1378, 1454, 1531, 1607, 1684, 1761,
1837, 1914, 1990, 2067, 2143, 2220, 2296, 2373, 2449, 2526, 2602, 2679,
2756, 2832, 2909, 2985, 3062, 3138, 3215, 3291, 3368, 3444, 3521, 3598,
3674, 3751, 3827, 3904, 3980, 4057, 4133, 4210, 4286, 4363, 4440, 4516,
4593, 4669, 4746, 4822, 4899, 4975, 5052, 5128, 5205, 5282, 5358, 5435,
5511, 5588, 5664, 5741, 5817, 5894, 5970, 6047, 6124, 6200, 6277, 6353,
6430, 6506, 6583, 6659, 6736, 6812, 6889, 6966, 7042, 7119, 7195, 7272,
7348, 7425, 7501, 7578, 7654, 7731, 7807, 7884, 7961, 8037, 8114, 8190,
8267, 8343, 8420, 8496, 8573, 8649, 8726, 8803, 8879, 8956, 9032, 9109,
9185, 9262, 9338, 9415, 9491, 9568, 9645, 9721, 9798, 9874, 9951,10027,
10104,10180,10257,10333,10410,10487,10563,10640,10716,10793,10869,10946,
11022,11099,11175,11252,11329,11405,11482,11558,11635,11711,11788,11864,
11941,12017,12094,12170,12247,12324,12400,12477,12553,12630,12706,12783,
12859,12936,13012,13089,13166,13242,13319,13395,13472,13548,13625,13701,
13778,13854,13931,14008,14084,14161,14237,14314,14390,14467,14543,14620,
14696,14773,14850,14926,15003,15079,15156,15232,15309,15385,15462,15538,
15615,15692,15768,15845,15921,15998,16074,16151,16227,16304,16380,16457,
16534,16610,16687,16763,16840,16916,16993,17069,17146,17222,17299,17375,
17452,17529,17605,17682,17758,17835,17911,17988,18064,18141,18217,18294,
18371,18447,18524,18600,18677,18753,18830,18906,18983,19059,19136,19213,
19289,19366,19442,19519 };
int mul150[256] = {
0, 150, 301, 451, 601, 751, 902, 1052, 1202, 1352, 1503, 1653,
1803, 1954, 2104, 2254, 2404, 2555, 2705, 2855, 3005, 3156, 3306, 3456,
3607, 3757, 3907, 4057, 4208, 4358, 4508, 4658, 4809, 4959, 5109, 5260,
5410, 5560, 5710, 5861, 6011, 6161, 6311, 6462, 6612, 6762, 6913, 7063,
7213, 7363, 7514, 7664, 7814, 7964, 8115, 8265, 8415, 8566, 8716, 8866,
9016, 9167, 9317, 9467, 9617, 9768, 9918,10068,10218,10369,10519,10669,
10820,10970,11120,11270,11421,11571,11721,11871,12022,12172,12322,12473,
12623,12773,12923,13074,13224,13374,13524,13675,13825,13975,14126,14276,
14426,14576,14727,14877,15027,15177,15328,15478,15628,15779,15929,16079,
16229,16380,16530,16680,16830,16981,17131,17281,17432,17582,17732,17882,
18033,18183,18333,18483,18634,18784,18934,19085,19235,19385,19535,19686,
19836,19986,20136,20287,20437,20587,20738,20888,21038,21188,21339,21489,
21639,21789,21940,22090,22240,22391,22541,22691,22841,22992,23142,23292,
23442,23593,23743,23893,24044,24194,24344,24494,24645,24795,24945,25095,
25246,25396,25546,25697,25847,25997,26147,26298,26448,26598,26748,26899,
27049,27199,27350,27500,27650,27800,27951,28101,28251,28401,28552,28702,
28852,29002,29153,29303,29453,29604,29754,29904,30054,30205,30355,30505,
30655,30806,30956,31106,31257,31407,31557,31707,31858,32008,32158,32308,
32459,32609,32759,32910,33060,33210,33360,33511,33661,33811,33961,34112,
34262,34412,34563,34713,34863,35013,35164,35314,35464,35614,35765,35915,
36065,36216,36366,36516,36666,36817,36967,37117,37267,37418,37568,37718,
37869,38019,38169,38319 };
int mul29[256] = {
0, 29, 58, 87, 117, 146, 175, 204, 234, 263, 292, 321,
350, 379, 408, 438, 467, 496, 525, 555, 584, 613, 642, 671,
700, 729, 759, 788, 817, 846, 876, 905, 934, 963, 993, 1021,
1050, 1080, 1109, 1138, 1167, 1197, 1226, 1255, 1284, 1314, 1342, 1371,
1401, 1430, 1459, 1488, 1518, 1547, 1576, 1605, 1635, 1663, 1692, 1722,
1751, 1780, 1809, 1839, 1868, 1897, 1926, 1956, 1985, 2013, 2043, 2072,
2101, 2130, 2160, 2189, 2218, 2247, 2277, 2306, 2334, 2364, 2393, 2422,
2451, 2481, 2510, 2539, 2568, 2598, 2627, 2655, 2685, 2714, 2743, 2772,
2802, 2831, 2860, 2889, 2919, 2948, 2977, 3006, 3035, 3064, 3093, 3123,
3152, 3181, 3210, 3240, 3269, 3298, 3327, 3356, 3385, 3414, 3444, 3473,
3502, 3531, 3561, 3590, 3619, 3648, 3677, 3706, 3735, 3765, 3794, 3823,
3852, 3882, 3911, 3940, 3969, 3998, 4027, 4056, 4086, 4115, 4144, 4173,
4203, 4232, 4261, 4290, 4319, 4348, 4377, 4407, 4436, 4465, 4494, 4524,
4553, 4582, 4611, 4641, 4669, 4698, 4728, 4757, 4786, 4815, 4845, 4874,
4903, 4932, 4962, 4990, 5019, 5049, 5078, 5107, 5136, 5166, 5195, 5224,
5253, 5283, 5311, 5340, 5370, 5399, 5428, 5457, 5487, 5516, 5545, 5574,
5604, 5633, 5661, 5691, 5720, 5749, 5778, 5808, 5837, 5866, 5895, 5925,
5954, 5982, 6012, 6041, 6070, 6099, 6129, 6158, 6187, 6216, 6246, 6275,
6303, 6333, 6362, 6391, 6420, 6450, 6479, 6508, 6537, 6567, 6596, 6625,
6654, 6683, 6712, 6741, 6771, 6800, 6829, 6858, 6888, 6917, 6946, 6975,
7004, 7033, 7062, 7092, 7121, 7150, 7179, 7209, 7238, 7267, 7296, 7325,
7354, 7383, 7413, 7442 };
#else /* no needed */
extern int mul77[], mul150[], mul29[];
#endif
# endif /* RGB->GRAY lookup */
/*
* dithering matrix
*/
#ifdef CONVERT_TYPE
short dmatrix8[16][16] =
{
{ 1,235, 59,219, 15,231, 55,215, 2,232, 56,216, 12,228, 52,212},
{129, 65,187,123,143, 79,183,119,130, 66,184,120,140, 76,180,116},
{ 33,193, 17,251, 47,207, 31,247, 34,194, 18,248, 44,204, 28,244},
{161, 97,145, 81,175,111,159, 95,162, 98,146, 82,172,108,156, 92},
{ 9,225, 49,209, 5,239, 63,223, 10,226, 50,210, 6,236, 60,220},
{137, 73,177,113,133, 69,191,127,138, 74,178,114,134, 70,188,124},
{ 41,201, 25,241, 37,197, 21,255, 42,202, 26,242, 38,198, 22,252},
{169,105,153, 89,165,101,149, 85,170,106,154, 90,166,102,150, 86},
{ 3,233, 57,217, 13,229, 53,213, 0,234, 58,218, 14,230, 54,214},
{131, 67,185,121,141, 77,181,117,128, 64,186,122,142, 78,182,118},
{ 35,195, 19,249, 45,205, 29,245, 32,192, 16,250, 46,206, 30,246},
{163, 99,147, 83,173,109,157, 93,160, 96,144, 80,174,110,158, 94},
{ 11,227, 51,211, 7,237, 61,221, 8,224, 48,208, 4,238, 62,222},
{139, 75,179,115,135, 71,189,125,136, 72,176,112,132, 68,190,126},
{ 43,203, 27,243, 39,199, 23,253, 40,200, 24,240, 36,196, 20,254},
{171,107,155, 91,167,103,151, 87,168,104,152, 88,164,100,148, 84} };
#else /* somewhere else */
extern short dmatrix8[16][16];
#endif
#endif /* protect */